<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
                        <legend>商品数据</legend>
                    </fieldset>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">商品编号</label>
                            <div class="layui-input-inline">
                                <input type="text" lay-verify="required" lay-reqtext="商品编号不能为空"
                                       placeholder="请输入商品编号" name="productNum" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 查 询
                            </button>
                        </div>
                    </div>

                    <div style="margin-bottom: 15px;font-weight: bold;">查询结果</div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 200px">原访问量</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly id="clickNum" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 200px">商品的总访问量</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly id="visitsVolume" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 200px">商品的分享量</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly id="shareVolume" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 200px">被分享商品的点击量</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly id="shareClickVolume" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
                        <legend>专区数据</legend>
                    </fieldset>
                    <div class="layui-form-item">
                        <div class="layui-input-inline">
                            <select id="zoneid" lay-filter="zone">
                                <option value=''>选择专区</option>
                                <option value='pages_private_scene2/GroupPurchase/SummerHot'>爆款专区</option>
                                <option value='pages_private_scene2/GroupPurchase/BrandSale'>品牌特卖</option>
                                <option value='pages_private_scene2/GroupPurchase/RushPurchase'>9.9专区</option>
                            </select>
                        </div>
                        <div class="layui-inline">
                            <a href="#" class="layui-btn layui-btn-primary" onclick="searchZone()"><i class="layui-icon"></i> 查 询</a>
                        </div>
                    </div>

                    <div style="margin-bottom: 15px;font-weight: bold;">查询结果</div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 200px">访问量</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly id="zoneVisitsVolume" class="layui-input">
                            </div>
                        </div>
                    </div>

                </form>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>

    /*layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/behavior/statistics/list',
            method: 'POST',
            contentType: 'application/json',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "radio"},
                {
                    field: 'numbering', title: '序号', width: 60, align: 'center', templet: function (d) {
                        return d.LAY_INDEX; //返回序号
                    }
                },
                {field: 'behaviorId', title: '商品id', sort: true, align: 'center'},
                {field: 'goodsNo', title: '商品编号', sort: true, align: 'center'},
                {field: 'behaviorName', title: '商品名称', sort: true, align: 'center'},
                {field: 'clickNum', title: '原访问量', sort: true, align: 'center'},
                {field: 'visitsVolume', title: '商品的总访问量', sort: true, align: 'center'},
                {field: 'shareVolume', title: '商品的分享量', sort: true, align: 'center'},
                {field: 'shareClickVolume', title: '被分享商品的点击量', sort: true, align: 'center'},
            ]],
            limits: [50, 100, 150, 200, 250, 300],
            limit: 50,
            page: true,
            request: {
                pageName: 'pageNum',
                limitName: 'pageSize'
            },
            response: { //定义后端 json 格式，详细参见官方文档
                statusName: 'code', //状态字段名称
                statusCode: '200', //状态字段成功值
                msgName: 'msg', //消息字段
                countName: 'total', //总数字段
                dataName: 'rows' //数据字段
            },
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            // console.log("监听搜索操作data=", data)
            // 执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: data.field
            }, 'data');

            return false;
        });

        // 监听表格单选框选择
        table.on('radio(currentTableFilter)', function (obj) {
            // console.log("监听表格单线框选择=", obj);
        });
    });*/

    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            let productNum = data.field.productNum;
            if (!productNum) {
                layer.msg("请输入商品编号");
                return false;
            }
            /*let url = "/goods/clicks/".concat(productNum);
            $.get(url, function (result) {
                if (result.code != 200) {
                    layer.msg(result.msg)
                }
                $("#clickNum").val(result.data);
            });*/
            let url = "/behavior/statistics/query/".concat(productNum);
            $.get(url, function (result) {
                if (result.code != 200) {
                    layer.msg(result.msg)
                }
                if(result.data){
                    $("#clickNum").val(result.data.clickNum?result.data.clickNum:0);
                    $("#visitsVolume").val(result.data.visitsVolume?result.data.visitsVolume:0);
                    $("#shareVolume").val(result.data.shareVolume?result.data.shareVolume:0);
                    $("#shareClickVolume").val(result.data.shareClickVolume?result.data.shareClickVolume:0);
                }
            });
            return false;
        });


    });

    /**
     * 重载表格数据
     */
    function reloadTable() {
        /*layui.use(['table'], function () {
            let table = layui.table;
            table.reload('currentTableId', {
                url: '/behavior/statistics/list'
            });
        })*/
    }

    /**
     * 专区搜索
     */
    function searchZone() {
        let $ = layui.jquery
        let zone = $("#zoneid").find("option:selected").val();
        $.ajax({
            type: "post",
            url: '/behavior/statistics/query',
            data: JSON.stringify({behaviorId: zone}),
            dataType: 'json',
            contentType: 'application/json',
            success: function (req) {
                if (req.code == 200 && req.data.visitsVolume) {
                    $("#zoneVisitsVolume").val(req.data.visitsVolume);
                }else{
                    $("#zoneVisitsVolume").val("0");
                }
            },
            error: function (e) {
                $("#zoneVisitsVolume").val("");
            }
        })
    }

</script>

</body>
</html>
